package com.static_;

import org.w3c.dom.ls.LSOutput;

/**
 * @Author 小闽
 * @Date 2024/9/5 18:51
 * @PackageName: com.static_
 * @ClassName: StaticExercise02
 * @Description: 练习2
 * @Version 1.0
 */
public class StaticExercise02 {
    public static void main(String[] args) {
        System.out.println("Number of total is " + Person.getTotalPerson());  // 0
        Person p1 = new Person();
        System.out.println("Number of total is " + Person.getTotalPerson());  // 1
    }
}

class Person{
    // 非静态变量id
    private int id;
    // 静态变量total
    private static int total = 0;
    // 静态方法getTotalPerson，并返回total的值
    public static int getTotalPerson(){
//         id++; 错误
        return total;
    }

    /**
     * 构造方法
     */
    public Person() {
        total++;
        id = total;
    }
}
